from bank.Bank import Bank
from bank.BoatPosition import BoatPosition


class TreeNode:
    def __init__(self, left: Bank, right: Bank, parent=None, children=None, boat_position=BoatPosition.LEFT):
        if children is None:
            children = []
        self.left = left
        self.right = right
        self.parent = parent
        self.children = children
        self.boat_position = boat_position
        self.is_searched = False  # 只有叶子节点考虑这个属性，方便搜索所有路径

    def add_child(self, child):
        self.children.append(child)

    def is_leaf_node(self, number):
        return self.right.is_full(number) and self.left.is_empty() and self.boat_position == BoatPosition.RIGHT

    def reverse_boat_position(self):
        if self.boat_position == BoatPosition.LEFT:
            self.boat_position = BoatPosition.RIGHT
        elif self.boat_position == BoatPosition.RIGHT:
            self.boat_position = BoatPosition.LEFT

    def print_state(self):
        msg = 'left:' + str(self.left.preacher) + "/" + str(self.left.savage) + '  ' \
              + 'right:' + str(self.right.preacher) + "/" + str(self.right.savage) + "  boat:" + str(
            self.boat_position.value)
        print(msg)
